import cv2
# 加载图像
image = cv2.imread("images/dyc.jpg")
#image = cv2.imread("images/obama2.png")
#image = cv2.imread("images/messi.png")
#image = cv2.imread("images/messi2.png")
# 测试是否成功读取
image=cv2.resize(image,dsize=(768,1024))
cv2.imshow("raw",image)
cv2.waitKey(0)
# 进行灰度处理
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# cv2.imshow("gray",gray)
# cv2.waitKey(0)
# 加载人脸识别数据库
faceCascadePath = "cascades/haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(faceCascadePath)
faceRects = faceCascade.detectMultiScale(gray,scaleFactor=1.1,\
                                         minNeighbors=5,minSize=(30,30),\
                                         flags = cv2.CASCADE_SCALE_IMAGE)
for (x,y,w,h) in faceRects:
    cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),2)
cv2.imshow("Found {} faces in the picture".format(len(faceRects)),image)    
cv2.waitKey(0)
cv2.destroyAllWindows()
